package com.superlz.demo.security.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * AOP切片（可获取方法的参数的值 ）
 *
 * @Aspect：声明为切片的类
 *
 * 在什么时候起作用：
 * @Before
 * @After
 * @AfterThrowing
 * @Around
 *
 */
@Aspect
@Component
public class TimeAspect {

	/**
	 * execution:执行拦截的方法; *：任意方法； ..：任意参数
	 *
	 *
	 * @param pjp：方法的详细信息
	 * @return
	 * @throws Throwable
	 */
	@Around("execution(* com.superlz.demo.security.web.controller.UserController.*(..))")
	public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
		
		System.out.println("time aspect start");

		// 获取方法的参数
		Object[] args = pjp.getArgs();
		for (Object arg : args) {
			System.out.println("arg is "+arg);
		}
		
		long start = System.currentTimeMillis();

		// 调用执行被拦截的方法
		Object object = pjp.proceed();
		
		System.out.println("time aspect 耗时:"+ (System.currentTimeMillis() - start));
		
		System.out.println("time aspect end");
		
		return object;
	}

}
